package com.heima.bos.service;

import java.util.Set;

import javax.annotation.Resource;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.identity.Group;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.heima.bos.dao.DaoInter;
import com.heima.bos.dao.RoleDaoInter;
import com.heima.bos.domain.Function;
import com.heima.bos.domain.Role;
@Service
@Transactional
@SuppressWarnings("all")
public class RoleService extends BaseService<Role>{
	@Resource
	private RoleDaoInter roleDao;
	@Resource
	private ProcessEngine processEngine;
	/**
	 * 保存角色
	 * @param entity  角色
	 * @param ids	权限的ids
	 */
	public void save(Role entity, String ids) {
		roleDao.save(entity);//持久化对象
		//同步角色
		Group group = new GroupEntity();
		group.setId(entity.getName());
		processEngine.getIdentityService().saveGroup(group);
		
		Set functions = entity.getFunctions();
		String[] srr = ids.split(",");
		Function fun = null;
		for (String id : srr) {
			fun = new Function();
			fun.setId(id);
			functions.add(fun);
		}
	}
	@Override
	public DaoInter<Role> getDao() {
		return roleDao;
	}
}
